//
//  DiscountCollectionViewCell.m
//  Journey
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DiscountCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@interface DiscountCollectionViewCell ()

@end


@implementation DiscountCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubview];
    }
    return self;
}
-(void)createSubview
{
    self.image = [[UIImageView alloc] init];
    [self.contentView addSubview:self.image];
   // self.image.backgroundColor = [UIColor lightGrayColor];
    self.titleLabel = [[UILabel alloc] init];
  //  self.titleLabel.backgroundColor = [UIColor redColor];
    self.titleLabel.numberOfLines = 2;
    [self.contentView addSubview:self.titleLabel];
    self.priceoffLabel = [[UILabel alloc] init];
 //   self.priceoffLabel.backgroundColor = [UIColor redColor];
    self.priceoffLabel.textColor = [UIColor grayColor];
   
    [self.contentView addSubview:self.priceoffLabel];
    self.priceLabel = [[UILabel alloc] init];
   // self.priceLabel.backgroundColor = [UIColor redColor];
    self.priceLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:self.priceLabel];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.image.frame = CGRectMake(0 , 0 , 185 * WIDTHC, 100 * WIDTHC);
    self.titleLabel.frame = CGRectMake(0 , 100 * WIDTHC, 180 * WIDTHC, 50 * WIDTHC);
    self.priceoffLabel.frame = CGRectMake(0 , 150 * WIDTHC, 50 * WIDTHC, 30 * WIDTHC);
    self.priceLabel.frame = CGRectMake(100 * WIDTHC, 150 * WIDTHC, 90 * WIDTHC, 30 * WIDTHC);
}


-(void)setDiscount:(DiscountModel *)discount{
    _discount = discount;
    [self.image sd_setImageWithURL:[NSURL URLWithString:_discount.photo] placeholderImage:[UIImage imageNamed:@"image2"]];
    self.titleLabel.text = _discount.title;
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.priceoffLabel.text = _discount.priceoff;
     self.priceoffLabel.font = [UIFont systemFontOfSize:13];
    
 //   self.priceLabel.text = [_discount.price substringWithRange:NSMakeRange(4, 7)];
    NSRegularExpression *regular = [NSRegularExpression regularExpressionWithPattern:@"[a-zA-Z.<,>,/]" options:0 error:NULL];
    NSString *string = _discount.price;
    NSString *price= [regular stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@""];
    self.priceLabel.text = price;
   
}



@end
